package com.newx.common.core.enums.business;

import com.newx.common.core.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * DeFi借币订单状态枚举
 */
@Getter
@AllArgsConstructor
public enum LendOrderStatusEnum {
    /**
     * 在借订单
     */
    NOW(0, "在借订单"),
    /**
     * 待审核状态
     */
    AWAIT(1, "待审核"),

    /**
     * 审核通过状态
     */
    PASS(2, "审核通过"),

    /**
     * 审核拒绝状态
     */
    REJECT(3, "审核拒绝"),

    /**
     * 已逾期状态
     */
    OVERDUE(4, "已逾期"),

    /**
     * 已结清状态
     */
    SETTLE(5, "已结清"),
    /**
     * 完成订单
     */
    END(6, "完成订单"),
    ;

    /**
     * 状态码
     */
    private final Integer code;

    /**
     * 状态描述
     */
    private final String info;
    //根据code返回枚举
    public static LendOrderStatusEnum getEnumByCode(Integer code) {
        for (LendOrderStatusEnum lendOrderStatusEnum : values()) {
            if (Objects.equals(code, lendOrderStatusEnum.getCode())) {
                return lendOrderStatusEnum;
            }
        }
        throw new ServiceException("订单状态不存在");
    }
}
